package id842排列数字;

import java.util.Scanner;

public class Main {
    static int n ;
    static StringBuilder sb = new StringBuilder();
    //标记数字是否用过
    static boolean[] flag;
    public static void main(String[]args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        flag = new boolean[n+1];
        dfs(0);
    }

    static void dfs(int cur){
        if(cur == n){
            System.out.println(sb.toString());
            return;
        }

        for(int i = 1;i<=n;i++){
            if(!flag[i]){
                sb.append(i+" ");
                flag[i] = true;
                dfs(cur+1);
                flag[i] = false;
                sb.deleteCharAt(sb.length()-1);
                sb.deleteCharAt(sb.length()-1);
            }
        }
    }
}

